import SwiperAnimateCn from 'swiper-animate-cn'
import {
  clickBanner
} from "@api/login.js";
export default {
  name: 'public-banner',
  props: ["bannerlists"],
  data() {
    return {
      swiperOption: {
        // some swiper options/callbacks
        // 所有的参数同 swiper 官方 api 参数
        // ...
        init: false,
        autoplay: {
          delay: 4000
        },
        pagination: {
          el: '.swiper-pagination',
          clickable: true,
        }
      },
      // banner:this.bannerlists,
      bannerList: this.bannerlists
    };
  },
  created() {
    this.bannerList =this.bannerlists;
    setTimeout(() => {
      this.swiper.init()
    }, 30)
  },
  watch: {
    bannerList(nv,ov){
      this.bannerList =nv;
      //console.log('监听banner',this.bannerList)
    }
  },
  mounted() {
    ////console.log('这里i',this.bannerList)
    let that = SwiperAnimateCn
    // current swiper instance
    // 然后你就可以使用当前上下文内的swiper对象去做你想做的事了
    //this.swiper.slideTo(0, 1000, false)
    // this.swiper.on('setTransition', function (transition) {
    //   for (var i = 0; i < that2.swiper.slides.length; i++) {
    //     var slide = that2.swiper.slides.eq(i)
    //     slide.transition(transition);
    //   }
    // })
    this.swiper.on('init', function () {
      that.swiperAnimateCache(this.activeIndex) //隐藏动画元素
      that.swiperAnimate(this) //初始化完成开始动画
    })

    this.swiper.on('slideChangeTransitionStart', function () {
      that.swiperAnimate(this) //每个slide切换结束时也运行当前slide动画
    })
  },
  methods: {
    getPoint(item){
      var param ={
        id:item.id
      }
      clickBanner(param).then(res=>{
        window.location.href =item.url;
      })
    }
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.swiper
    }
  }
}